﻿using System;
using EchoFramework;
using UnityEngine;

/// <summary>
/// 游戏入口
/// </summary>
public class GameEntry : Singleton<GameEntry>
{
    /// <summary>
    /// 是否启用AB包模式
    /// </summary>
    [Header("AB包模式")]
    public bool AssetBundleMode;

    private void Awake()
    {
#if !UNITY_EDITOR
        AssetBundleMode = true;
#endif
        GameLogger.LogYellow("是否启用AB包模式：" + AssetBundleMode);
        DontDestroyOnLoad(gameObject);
        Application.targetFrameRate = -1;
       
        GameLogger.Instance.OnAwake();
        TimeManager.Instance.OnAwake();
        EventManager.Instance.OnAwake();
        LogicModuleManager.Instance.OnAwake();
        UIViewManager.Instance.OnAwake();
        SpriteManager.Instance.OnAwake();
        AssetManager.Instance.OnAwake();
    }

    private void Start()
    {
        GameLogger.Instance.OnStart();
        TimeManager.Instance.OnStart();
        EventManager.Instance.OnStart();
        LogicModuleManager.Instance.OnStart();
        UIViewManager.Instance.OnStart();
        SpriteManager.Instance.OnStart();
        AssetManager.Instance.OnStart(AfterStart);
    }

    private void Update()
    {
        GameLogger.Instance.OnUpdate();
        TimeManager.Instance.OnUpdate();
        EventManager.Instance.OnUpdate();
        LogicModuleManager.Instance.OnUpdate();
        UIViewManager.Instance.OnUpdate();
        SpriteManager.Instance.OnUpdate();
        AssetManager.Instance.OnUpdate();
    }

    private void FixedUpdate()
    {
        GameLogger.Instance.OnFixedUpdate();
        EventManager.Instance.OnFixedUpdate();
        TimeManager.Instance.OnFixedUpdate();
        LogicModuleManager.Instance.OnFixedUpdate();
        UIViewManager.Instance.OnFixedUpdate();
        SpriteManager.Instance.OnFixedUpdate();
        AssetManager.Instance.OnFixedUpdate();
    }

    /// <summary>
    /// 初始化之后的操作
    /// </summary>
    private void AfterStart()
    {
        GameLogger.Log("执行AfterInit");
    }

    private void OnDestroy()
    {
        GameLogger.Instance.OnClose();
        EventManager.Instance.OnClose();
        TimeManager.Instance.OnClose();
        LogicModuleManager.Instance.OnClose();
        UIViewManager.Instance.OnClose();
        SpriteManager.Instance.OnClose();
        AssetManager.Instance.OnClose();
    }

}